package org.dromara.iot.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.dromara.common.mqtt.domain.CustomMqttClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description : 测试类
 * @Author : lsyong
 * @Date : 2023/8/1 16:35
 */
@SaIgnore
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/iot/mqtt")
public class MqttController {

    @Resource
    private CustomMqttClient customMqttClient;

    @GetMapping(value = "/publishTopic")
    public String publishTopic(String topic, String sendMessage) {
        System.out.println("topic:" + topic);
        System.out.println("message:" + sendMessage);
        customMqttClient.publish(false, topic, sendMessage);
        return "topic:" + topic + "\nmessage:" + sendMessage;
    }

}
 